package com.itwjr.jdbc2.DataSorce;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class Demo1 {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource;
        //直接创建一个连接池
        DruidDataSource dataSource4druid = new DruidDataSource();
        dataSource4druid.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource4druid.setUrl("jdbc:mysql://127.0.0.1:3306/db1?useSSL=false");
        dataSource4druid.setUsername("root");
        dataSource4druid.setPassword("1234");


        dataSource = dataSource4druid;

        //调用连接池的获取方法
        Connection connection = dataSource.getConnection();
        System.out.println(connection);

        //归还连接池
        connection.close();


    }
}
